package com.jl.card.stk;

import java.util.HashMap;

import com.jl.card.Card;
import com.jl.card.CardManager;
import com.jl.card.ISTK;
import com.jl.card.RefreshListenner;

public class STKManager implements RefreshListenner {

	private static STKManager mgr;

	private HashMap<Card, ISTK> map = new HashMap<Card, ISTK>();

	private STKManager() {
	};

	public synchronized static STKManager getInstance() {
		if (mgr == null) {
			mgr = new STKManager();
			CardManager.getInstance(false).addRefreshListenner(mgr);
		}
		return mgr;
	}

	public ISTK getSTK(Card card) {
		if (map.containsKey(card)) {
			return map.get(card);
		} else {
			ISTK stk = card.getProvider().getSTKOperation(card);
			map.put(card, stk);
			return stk;
		}
	}

	@Override
	public void refresh() {
		map.clear();
	}

}
